class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(head==NULL||head->next==NULL) return head;
          ListNode* h=head,*p=h->next,*t=head;
          int index=0;
          if(h->val==p->val){
            index=1;
          }
          while(h!=NULL){
            p=h->next;
            if(p!=NULL&&h->val==p->val){
              while(p!=NULL&&p->val==h->val){
                p=p->next;
              }
              t->next=p;
              h=p;
            }else{
              t=h;
              h=h->next;
            }
          }
          if(index==1){
            head=head->next;
          }
          return head;
    }
};
